package com.shopmall.controller.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shopmall.common.ResponseData;
import com.shopmall.system.entity.UserInfo;
import com.shopmall.system.service.IUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys")
public class UserInfoController extends ResponseData {
    @Autowired
    private IUserInfoService userInfoService;

    @PostMapping("/userList")
    public ResponseData getUserList(@RequestBody UserInfo userInfo){
        IPage<UserInfo> userInfoIPage = userInfoService.userList(userInfo);
        return success(userInfoIPage);
    }

    @PostMapping("/userAddorUpdate")
    public ResponseData userAddorUpdate(@RequestBody UserInfo userInfo){
        int i = userInfoService.addOrUpdate(userInfo);
        if(i>0){
            return success("操作成功");
        }
        return failed("操作失败");
    }

    @GetMapping("/userDelById/{id}")
    public ResponseData userDelById(@PathVariable Integer id){
        int i = userInfoService.deleteById(id);
        if(i>0){
            return success("操作成功");
        }
        return failed("操作失败");
    }

    @PostMapping("/updatePassword")
    public ResponseData updatePassword(@RequestBody UserInfo userInfo){
        int i = userInfoService.updatePassword(userInfo);
        if(i>0){
            return success("操作成功");
        }
        return failed("操作失败");

    }

}
